package com.bvbot.core.extractor;

import static com.bvbot.core.Logger.log;
import static com.bvbot.core.tools.StreamUtils.properClose;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class UrlHtmlExtractor {

	public String getHtml(String urlAsString) {
		String result = null;
		BufferedReader in = null;
		try {
			URL url = new URL(urlAsString);
			in = new BufferedReader(new InputStreamReader(url.openStream()));
			String inputLine;
			StringBuilder content = new StringBuilder();
			while ((inputLine = in.readLine()) != null) {
				content.append(inputLine);
			}
			result = content.toString();
		} catch (Exception e) {
			log("Impossible to get content from " + urlAsString + " : "
					+ e.getMessage(), e);
		} finally {
			properClose(in);
		}
		return result;
	}

}
